package com.pb.camera.more.utils;


import java.text.Format;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;

public class TimeUtils {
    public static String FORMAT_MODE_1 = "HH:mm";
    public static String FORMAT_MODE_2 = "MM:dd";

    /**
     * 获得歌曲的时间
     *
     * @param time
     * @return
     */
    public static long getTime(String time) {
        long mLongTime = 0;
        if (time.contains(":")) {
            String[] split = time.split(":");
            mLongTime = Long.parseLong(split[0]) * 60 + Long.parseLong(split[1]);
        }

        return mLongTime;
    }

    public static String getStringTime(long time) {
        String hour = "";
        if (time <= 0)
            return "0:00";
        if (time >= 3600) {
            hour = (int) (time / 3600) + ":";
        }
        long seconds = time % 60;
        long minutes = (time / 60) % 60;
        return hour + String.valueOf(minutes) + ":" + (seconds < 10 ? "0" + seconds : seconds);
    }

    public static String stampsToReal(String formatMode, long timestamps) {
        SimpleDateFormat format = new SimpleDateFormat(formatMode);
        if (timestamps == -1) //得到当前的小时和分钟
            return format.format(new Date());       //时区转化，下面的转化是以格林威治时间为标准，我们早在东八区，所以要转一下*/
        Date date = new Date((timestamps) * 1000);
        return format.format(date);
    }
}
